home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / VIVIDUS / QD3D.SIT / qd3d / Cqd3dPort.h < prev    next >
C/C++ Source or Header  |  1991-10-04  |  7KB  |  225 lines

  1. #pragma    once
  2. #include    <vect.h>
  3.  
  4.  
  5. /*    ======================================================================
  6.  
  7.     This header file is Copyright 1991 by Vividus Consulting.
  8.     
  9.     This is not public domain source code.  You may not copy and
  10.     paste from this source code.  Read your Vividus Licensing
  11.     agreement for details and other restrictions.
  12.     
  13.     This header file is for anything that uses the qd3d Vividus
  14.     Source Code Library.
  15.  
  16.     ======================================================================    */
  17.  
  18. //    Projection types served by this class.
  19. enum {
  20.     kqd3dPortPerspective = 0,
  21.     kqd3dPortParallel
  22. };
  23.  
  24. class    Cqd3dPort : indirect    {
  25.     public:
  26.                                 /*    Public read only instance variables:        */
  27.                                     
  28.         vector        Ua2f;            /*    Unit vector pointing from at to eye.    */
  29.         int            type;            /*    Projection type.                        */
  30.     
  31.         vector        tmat[3],        /*    Eye coordinate transformation matrix.    */
  32.                     tmatinv[3];        /*    Inverse transformation matrix.            */
  33.     
  34.                                 /*    PRIVATE instance variables:                    */
  35.                                 /*        Use these at your own risk!                */
  36.                                     
  37.         vector        f,                /*    Eye position.                            */
  38.                     a,                /*    Center of attention.                    */
  39.                     u;                /*    "Up" vector of eye.                        */
  40.         double        v;                /*    View angle.  (perspective proj.)        */
  41.         double        al, ar, at, ab;    /*    EC view rectangle.  (parallel proj.)    */
  42.     
  43.         GWorldPtr    gw;                /*    The GWorld to draw into.                */
  44.         GrafPtr        gp;                /*    The GrafPort to draw to.                */
  45.                                     /*    Both are not concurrently used.            */
  46.         Rect        vport;            /*    The portion of the QuickDraw            */
  47.                                     /*        environment to draw to.                */
  48.     
  49.         unsigned int *zbuff,        /*    The z-buffer.                            */
  50.                     *zbufflast,
  51.                     zbuffwidth;
  52.                     
  53.         Boolean        onlyqd,            /*    Only use quickdraw operations.  Ie.     */
  54.                                     /*    No gouraud shaded polygons or linear    */
  55.                                     /*    blended color lines.                    */
  56.                     cullbacks,        /*    True = hide, False = show.                */
  57.                     usezbuff,        /*    If applicable, attempt to use            */
  58.                                     /*        zbuffer.                            */
  59.                     usedepthque,    /*    Depth que to the background                */
  60.                                     /*        color.                                */
  61.                     wireframe;        /*    Map all fill calls to frame calls.        */
  62.                                     
  63.         int            lastError;        /*    The last recorded qd3d error.  Error    */
  64.                                     /*        codes listed below.                    */
  65.     
  66.         Fixed        fFract;            /*    Depth queue:  fraction of depth color    */
  67.                                     /*      at far plane.                            */
  68.         FixedVector    dColor;            /*    Depth queue:  background color to blend    */
  69.                                     /*      to.                                    */
  70.                                     
  71.         double        zMin, zMax;        /*    Near and far planes (EC.z).                */
  72.         int            pwidth,            /*    Projection constants and coefficients.    */
  73.                     plength, 
  74.                     pmin;
  75.         double        pb, pd, pe, pf;
  76.         int            pa, pc;
  77.     
  78.         vector        position,        /*    These are for MoveTo and LineTo.        */
  79.                     color;
  80.         
  81.                                 /*    Public methods:                                */
  82.         void        Init(void);
  83.         void        SetQDEnviron(void);
  84.         void        SetQDRect(Rect    *r);
  85.         void        Set3dPort(void);
  86.         void        Dispose(void);
  87.     
  88.         void        Erase(void);
  89.         void        DrawOrigin(double size);
  90.         
  91.         void        SetView(
  92.                         vector *f,
  93.                         vector *a,
  94.                         vector *u);
  95.         void        GetView(
  96.                         vector *f,
  97.                         vector *a,
  98.                         vector *u);
  99.         void        SetPolarView(
  100.                         vector *a,
  101.                         double rho,
  102.                         double theta,
  103.                         double phi,
  104.                         double twist);
  105.         void        GetPolarView(
  106.                         vector *a,
  107.                         double *rho,
  108.                         double *theta,
  109.                         double *phi,
  110.                         double *twist);
  111.         int            GetProjectionType(void);
  112.         void        SetPerspective(
  113.                         double v,
  114.                         double near,
  115.                         double far);
  116.         void        GetPerspective(
  117.                         double *v,
  118.                         double *near,
  119.                         double *far);
  120.         void        SetParallel(
  121.                         vector *upperLeft,
  122.                         vector *lowerRight,
  123.                         double near,
  124.                         double far);
  125.         void        GetParallel(
  126.                         vector *upperLeft,
  127.                         vector *lowerRight,
  128.                         double *near,
  129.                         double *far);
  130.         
  131.         int            Qd3dError(void);
  132.         
  133.         Boolean        GetOnlyQD(void);
  134.         void        SetOnlyQD(Boolean onOff);
  135.         Boolean        GetCullBacks(void);
  136.         void        SetCullBacks(Boolean onOff);
  137.         Boolean        GetUseZBuff(void);
  138.         void        SetUseZBuff(Boolean onOff);
  139.         Boolean        GetDepthQue(void);
  140.         void        SetDepthQue(
  141.                         Boolean onOff,
  142.                         vector *fadeColor,
  143.                         double furthestFraction);
  144.         Boolean        GetWireframe(void);
  145.         void        SetWireframe(Boolean onOff);
  146.                         
  147.                                 /*    Private methods:                            */
  148.                                 /*        Use these at your own peril.            */
  149.     protected:
  150.         void        BuildTMat(void);
  151.         void        BuildProj(void);
  152. };
  153.  
  154. /*    Public functions"                                                        */
  155. Cqd3dPort *    Get3dPort(void);
  156. int            Qd3dError(void);
  157.  
  158. /*    Presently defined error codes:                                            */
  159. /* #define    noErr        noErr                                                */
  160. #define        noZBuffMem    1    /*    Z-Buffer memory was unable to be allocated.    */
  161. #define        moveOutVV    2    /*    MoveTo outside of present view volume.        */
  162.  
  163. /*    ======================================================================    */
  164. /*    Public 3d primitives:                                                    */
  165.  
  166. #define PolyMaxN    10    /*    The maximum number of vertices in a polygon.    */
  167.  
  168. void    Transform(int n, vector x[], vector xe[]);
  169. void    Project(int n, vector xe[], vector xp[]);
  170. void    TransformProject(int n, vector x[], vector xp[]);
  171.  
  172. void    MoveTo3d(vector *x);
  173. void    LineTo3d(vector    *x);
  174. void    Poly3dMark(int n, vector x[], void (*markf)(vector *pos));
  175. void    Poly3dLine(int n, vector x[]);
  176. void    Poly3dFrame(int n, vector x[]);
  177. void    Poly3dFrameErase(int n, vector x[]);
  178. void    Poly3dFill(int n, vector x[]);
  179. void    Poly3dErase(int n, vector x[]);
  180. void    PolyC3dMark(int n, vector x[], void (*markf)(vector *pos), vector c[]);
  181. void    PolyC3dLine(int n, vector x[], vector c[]);
  182. void    PolyC3dFrame(int n, vector x[], vector c[]);
  183. void    PolyC3dFill(int n, vector x[], vector c[]);
  184.  
  185. /*    ======================================================================    */
  186. /*    Public default marking functions:                                        */
  187.  
  188. #define        CNTRLWDTH    2    /*    Half the width of the control rep.            */
  189. #define        SLTNWDTH    4    /*    Half the width of the selected control rep    */
  190.  
  191. void    MarkPoint(vector *pos);
  192. void    MarkSelectedPoint(vector *pos);
  193. void    MarkCtrlPoint(vector *pos);
  194.  
  195. /*    ======================================================================    */
  196. /*    Public color primitives:                                                */
  197.  
  198. void    Color2RGB(vector *c, RGBColor *rgb);
  199. void    RGB2Color(RGBColor *rgb, vector *c);
  200. void    vForeColor(vector *c);
  201.  
  202. /*    ======================================================================    */
  203. /*    Private 3d primitives:                                                    */
  204.  
  205. Boolean    Line3dClip(vector *p1, vector *p2, vector *cp1, vector *cp2);
  206. Boolean    LineC3dClip(
  207.     vector *p1, vector *p2, vector *cp1, vector *cp2, 
  208.     vector *inc1, vector *inc2, vector *outc1, vector *outc2);
  209. void    Clip3d(int *n, vector inndc[], vector outndc[]);
  210. void    ClipC3d(int *n, vector inndc[], vector outndc[], vector inc[], vector outc[]);
  211. void    TranClipProjf(int *n, vector in[], FixedVector outdc[]);
  212. void    TranClipProjCf(int *n, vector in[], FixedVector outdc[], vector inc[], vector outc[]);
  213. void    Projectf(int n, vector xe[], FixedVector xp[]);
  214. void    TransformProjectf(int n, vector x[], FixedVector xt[]);
  215. void    ndc2fdc(int n, vector *v, FixedVector *fv);
  216.  
  217. /*    ======================================================================    */
  218. /*    Private color primitives:                                                */
  219.  
  220. void    Color2RGB(vector *c, RGBColor *rgb);
  221. void    RGB2Color(RGBColor *rgb, vector *c);
  222. void    GetFColor(vector *c, FixedVector *fc);
  223. void    DepthColor(FixedVector *inc, Fixed z, FixedVector *oc);
  224. void    cv2rgb(FixedVector *f, RGBColor *rgb);
  225. void    rgb2cv(RGBColor *rgb, FixedVector *f);